package com.woniuxy.cloud.userassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.cloud.entity.TGoodCar;
import com.woniuxy.cloud.entity.TServiceCar;
import com.woniuxy.cloud.form.AddServiceCarForm;
import com.woniuxy.cloud.userassembly.mapper.TServiceCarMapper;
import com.woniuxy.cloud.userassembly.service.ITServiceCarService;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务项目购物车表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-09-24
 */
@Service
public class TServiceCarServiceImpl extends ServiceImpl<TServiceCarMapper, TServiceCar> implements ITServiceCarService {

    /**
     * 根据服务购物车id查询
     * @param serviceCarServiceId 服务购物车id
     * @return Result
     */
    @Override
    public TServiceCar getServiceCarByServiceCarId(Integer serviceCarServiceId) {
        return getBaseMapper().selectById(serviceCarServiceId);
    }


    /**
     * 查询重复的服务购物车
     * @param userId 用户id
     * @param serviceCarSecondServiceId 二级服务服务id
     * @return
     */
    @Override
    public TServiceCar getServiceCarByUserIdAndServceId(Integer userId,Integer serviceCarSecondServiceId){
        QueryWrapper<TServiceCar> wrapper = new QueryWrapper<>();
         wrapper.eq("service_car_user_id",userId).eq("service_car_second_service_id",serviceCarSecondServiceId);
         return getBaseMapper().selectOne(wrapper);
    }


    /**
     * 新增服务购物车
     * @param tServiceCar
     * @return
     */
    @Override
    public Integer insertServiceCar(TServiceCar tServiceCar) { ;
        return getBaseMapper().insert(tServiceCar);
    }

    /**
     * 修改服务商品数量
     * @param serviceCarId
     * @param serviceCarNum
     * @return Result
     */
    @Override
    public Integer updateServiceCarNum(Integer serviceCarId, Integer serviceCarNum,Double total) {
        UpdateWrapper<TServiceCar> wrapper = new UpdateWrapper<>();
        wrapper.eq("service_car_id",serviceCarId).set("service_car_num",serviceCarNum).set("service_car_total",total);
        return getBaseMapper().update(null,wrapper);
    }


    /**
     * 移除服务购物车
     * @param serviceCarId
     * @return Result
     */
    @Override
    public Integer deleteServiceCar(Integer serviceCarId) {
        return  getBaseMapper().deleteById(serviceCarId);
    }


    /**
     * 查看用户所有服务购物车
     * @param userId 用户id
     * @return Result
     */
    @Override
    public List<TServiceCar> getServiceCarList(Integer userId) {
        QueryWrapper<TServiceCar> wrapper = new QueryWrapper<>();
        wrapper.eq("service_car_user_id",userId);
        return getBaseMapper().selectList(wrapper);
    }


    @Override
    public List<TServiceCar> getServiceCarListByIds(List<Integer> ids) {
        QueryWrapper<TServiceCar> tServiceCarQueryWrapper = new QueryWrapper<>();
        tServiceCarQueryWrapper.in("service_car_id",ids);
        List<TServiceCar> tGoodCars = getBaseMapper().selectList(tServiceCarQueryWrapper);
        return tGoodCars;
    }


}
